<?php

class Common_DataGateway_Database_Object {
    
    private $str_sql = null;
    private $obj_datagateway = null;
    
    public function __construct(Common_DataGateway_Database $obj_datagateway, $str_sql = null) {
        $this->setSql($str_sql);
        $this->setDataGateway($obj_datagateway);
    }
    
    public function setDataGateway(Common_DataGateway_Database $obj_datagateway) {
        $this->obj_datagateway = $obj_datagateway;
    }
    
    public function getDataGateway() {
        return $this->obj_datagateway;
    }
    
    public function issetSql() {
        return !is_null($this->str_sql);
    }
    
    public function getSql() {
        return $this->str_sql;
    }
    
    public function setSql($str_sql) {
        if(is_string($str_sql)) {
            $str_sql = trim($str_sql);
            if(stripos($str_sql, 'SELECT') === 0) {
                $this->str_sql = $str_sql;
            }
        }
    }
    
    public function getData() {
        
        $mix_results = null;
        
        if($this->issetSql()) {
            $str_sql = $this->getSql();
            $mix_results = $this->getDataGateway()->execute_query($str_sql);
        }
        
        return $mix_results;
    }
    
}
